import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils

@pytest.mark.skip
@allure.feature('TestCase_15: 猜方言游戏开始后，tts播报完成后，进入答题流程	 ')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001052964?url_cache_key=ab49d6eabe9823050826460ca132aea4')
class TestCaseCarpark15:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 车乐汇
        self.carpark_index_page = CommonPage(self.driver).get_carpark_index_page()
        self.carpark_recommend_page = CommonPage(self.driver).get_carpark_recommend_page()
        # 猜方言
        self.carpark_dialect_index_page = CommonPage(self.driver).get_carpark_guess_dialect_page()
        self.carpark_dialect_start_page = CommonPage(self.driver).get_carpark_dialect_start_page()
        self.carpark_dialect_game_page = CommonPage(self.driver).get_carpark_dialect_game_page()
        self.carpark_dialect_error_page = CommonPage(self.driver).get_carpark_dialect_error_page()
        self.carpark_quit_toast_page = CommonPage(self.driver).get_carpark_dialect_quit_page()
        self.carpark_settlement_page = CommonPage(self.driver).get_carpark_dialect_settlement_page()
        self.carpark_ranking_page = CommonPage(self.driver).get_carpark_dialect_ranking_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('carpark')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=151)
    def test_carpark_15_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的车乐汇图标")
    @pytest.mark.run(order=152)
    def test_carpark_15_2_click_carpark(self):
        try:
            self.launcher_app_list_page.click_appname("车乐汇")
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 点击游戏tab进入游戏,点击猜歌名进入猜歌名")
    @pytest.mark.run(order=153)
    def test_carpark_15_3_is_display_carpark(self):
        try:
            self.carpark_recommend_page.is_display_carpark_recommend()
            self.carpark_recommend_page.click_tab_game()
            self.carpark_index_page.is_display_carpark_index()
            self.carpark_index_page.click_list_name(index=3)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step4: 点击开始游戏,等待播放题目完成进入收音状态")
    @pytest.mark.run(order=154)
    def test_carpark_15_4_is_display_carpark(self):
        try:
            a = self.carpark_dialect_start_page.is_display_carpark_start()
            if a == False:
                self.carpark_dialect_index_page.click_download_immediately()
                time.sleep(30)
                self.carpark_dialect_start_page.is_display_carpark_start()
                self.carpark_dialect_start_page.click_start_game()
                self.carpark_dialect_game_page.is_display_carpark_game()
                time.sleep(30)
                print("播报完成,用例测试完成")
            else:
                self.carpark_dialect_start_page.click_start_game()
                self.carpark_dialect_game_page.is_display_carpark_game()
                time.sleep(30)
                print("播报完成,用例测试完成")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_carpark_15.py")
